package com.hhw.controller;


import com.hhw.mapper.UserMapper;
import com.hhw.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    private UserMapper userMapper;

//    查询全部用户方法
    @GetMapping("/queryUser")
    public List<User> queryUser(){
        List<User> userList = userMapper.queryUser();
        for (User user:userList){
            System.out.println(user);
        }
        return userList;
    }

//  添加一个用户
    @GetMapping("/addUser")
    public String addUser(){
        userMapper.addUser(new User(8,"小麦","666"));
        return "ok";
    }

//    删除一个用户
    @RequestMapping("/deleteUser")
    public String deleteUser(Integer id){
        userMapper.deleteUser(1);
        return "ok";
    }
//    修改用户
    @GetMapping("/updateUser")
    public String updateUser(User user){
        User update = userMapper.updateUser(new User(3, "虾米", "1234"));
        System.out.println(update.toString());
        return "ok";
    }
}
